/** 
    @file pixelworld.hpp
    @brief Game world
*/

#ifndef PM3_PIXELWORLD_HPP
#define PM3_PIXELWORLD_HPP

#include "interface.hpp"
#include "logger.hpp"
#include "pixelmap.hpp"
#include "pixelplayer.hpp"
#include "portal_debug.hpp"

namespace pm3 {
    /**
        @class PIXELWORLD
        @brief Game world
    */
    class PIXELWORLD: public Ogre::Singleton<PIXELWORLD>, LUA_SCRIPTED {
    friend class GAME;
    public:
            /**
                @brief Constructor
            */
            PIXELWORLD();
            /**
                @brief Destructor
            */
            ~PIXELWORLD();

            //! Pixel map
            PIXELMAP m_map;

            //! A player node
            PIXELPLAYER m_player;

            /**
                @brief Unloads the world
            */
            void unload();

            /**
                @brief Takes the next map
                @return True, if there is one. Otherwise false
            */
            bool next_map();

            /**
                @brief Takes the previous map
                @return True, if there is one. Otherwise false
            */
            bool prev_map();

            /**
                @brief Takes the next map
                @param[in] i_num Number of the map to select
                @return True, if there is one. Otherwise false
            */
            bool select_map( int i_num );

            /**
                @brief Gets the number of maps
                @return The number of maps in the world
            */
            inline int get_num_maps() const {
                return m_maps.size();
            }

            /**
                @brief Gets the id of the currently active map
                @return The id of the currently active map
            */
            inline int get_cur_map() const {
                return m_cur_map;
            }

            /**
                @brief Adds a map to the world
                @param[in] r_path Reference to the path of the map
                @return Number of maps in the list
            */
            int add_map( const std::string &r_path );

            /**
                @brief Updates the world
            */
            void update();

            /**
                @brief Dumps the world into the log
            */
            void dump() const;

            /**
                @brief Sets the world up
            */
            void init();

    protected:
            /**
                @brief Binds functions called by lua
            */
            void bind();

            /**
                @brief Process any messages that have been posted to the world
            */
            void process_messages();

            /**
                @brief Renders debug items
            */
            void debug_render();

            //! A list of maps in the world
            std::vector<std::string> m_maps;

            //! Current map index
            int m_cur_map;
    };

    //! World global
    extern PIXELWORLD g_world;
}

#endif

